package com.example.mylibrary;

import static android.content.ContentValues.TAG;
import android.app.Instrumentation;
import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class BarterRegisterPage {
    public static UiDevice device;
    public static Instrumentation instrumentation;

    @Before
    public void first() throws InterruptedException{
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device= UiDevice.getInstance(instrumentation);
        int width = device.getDisplayWidth();
        int height = device.getDisplayHeight();
        device.pressHome();
        Thread.sleep(2000);
        device.swipe(width-10,height/2,50,height/2,10);
        Thread.sleep(2000);
        UiObject2 barter = device.findObject(By.text("Barter"));
        barter.click();
        Thread.sleep(3000);
    }


    //    注册新用户
    @Test
    public void testRegister() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).setText("2019012515");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).click();
        Thread.sleep(1000);

    }


    @After
    public static void tearDown() {
        device.pressBack();
    }
}
